<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="include.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><spring:message code="title.document" /></title>
<link rel="stylesheet" href="${pageContext.request.contextPath}/<spring:theme code="css"/>" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/<spring:url value="public-resources/js/bootstrap.js" />"></script>
</head>
 
<body>
	<%@ include file="header.jsp" %>
	<div class="container-fluid">
		<div class="page-header">
			<h2>Create document</h2>		
		</div>
		<form:form method="POST" enctype="multipart/form-data"  cssClass="form-horizontal" commandName="document" action="${pageContext.request.contextPath}/document/add">
			<form:errors path="*" cssClass="alert alert-error"  element="div" />
			<div class="control-group">
				<label class="control-label"><spring:message code="label.document.name" /></label>
				<div class="controls">
					<form:input path="name"/>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label"><spring:message code="label.document.description" /></label>
				<div class="controls">
					<form:textarea path="description"/>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label"><spring:message code="label.document.content" /></label>
				<div class="controls">
					<input type="file" name="file" id="file" />
				</div>
			</div>
			<div class="control-group">
				<div class="controls">
					<input class="btn" type="submit" value="<spring:message code="button.add" />" />
				</div>
			</div>
		</form:form>
		<hr />
		<h3>Document List</h3>
		<table class="table table-bordered">
			<thead>
				<tr>
					<td><spring:message code="label.document.name" /></td>
					<td><spring:message code="label.document.description" /></td>
					<td>&nbsp;</td>
				</tr>
			</thead>
			<c:if  test="${!empty documents}">
			<tbody>
				<c:forEach items="${documents}" var="document">
				<tr>
					<td>${document.name }</td>
					<td>${document.description }</td>
					<td>
						<a class="btn btn-mini" href="${pageContext.request.contextPath}/document/download/${document.id}"><i class="icon-download"></i> <spring:message code="button.download" /></a>
						<a class="btn btn-mini btn-danger" href="${pageContext.request.contextPath}/document/delete/${document.id}"
							onclick="return confirm('Are you sure you want to delete this document?')"><i class="icon-remove"></i> <spring:message code="button.delete" /></a>
					</td>
				</tr>
				</c:forEach>
			</tbody>
			</c:if>
		</table>
	</div>
	<%@ include file="footer.jsp" %>
</body>
</html>